package com.deft.design.prototype.util;

import java.util.*;

/**
 * @author zdl
 * @description
 * @date 2022-04-21
 **/
public class TopicRandomUtil {

    public static Topic random(Map<String, String> option, String key) {
        Set<String> keySet = option.keySet();
        ArrayList<String> keyList = new ArrayList<>(keySet);
        Collections.shuffle(keyList);
        HashMap<String, String> optionNew = new HashMap<>(8);
        int idx = 0;
        String keyNew = null;
        for (String next : keySet) {
            String randomKey = keyList.get(idx++);
            if (key.equals(next)) {
                keyNew = randomKey;
            }
            optionNew.put(randomKey, option.get(next));
        }
        return new Topic(optionNew, keyNew);
    }
}
